﻿/******************************************************************************
 * 【本类功能概述】                                 					      *
 *  版权所有（C）2017-20XX，米兔网络                                         *
 *  保留所有权利。                                                            *
 ******************************************************************************
 *  作者 : <hughjk>
 *  创建时间: 2018年6月27日 16:10:42
 *  文件描述: 属性基础类
 *****************************************************************************/


using System.Collections.Generic;
using System.Text;
using UnityEngine;
using Util;

public enum AttrType {
    Str = 0,
    Agi = 1,
    Sta = 2,
    Elem = 3,
    Hp = 4,
    Mp = 5,
    Atk = 6,
    Def = 7,
    Acc = 8,
    Dod = 9,
    ElemAdd = 10,
    AtkSpd = 11,
    Cthr = 12,
    Cthd = 13,
    MoSpd = 14,
    HpRes = 15,
    MpRes = 16,
    CodAc = 17,
    FirAtk = 18,
    IceAtk = 19,
    PoiAtk = 20,
    EleAtk = 21,
    LigAtk = 22,
    DarAtk = 23,
    FirDef = 24,
    IceDef = 25,
    PoiDef = 26,
    EleDef = 27,
    LigDef = 28,
    DarDef = 29,
    Weight=30,
    Shield=31,
    Max,
}
public class Attr
{
    //Str       = 0 ;           //数值  //力量强度(Strength)
    //Agi       = 1 ;           //数值  //敏捷强度(Agility)
    //Sta       = 2 ;           //数值  //体力强度(Stamina)
    //Elem      = 3 ;           //数值  //元素亲和(Element)
    //Hp        = 4 ;           //数值  //生命值(Health Point)
    //MaxHp     =   ;           //数值  //最大生命值(Health Point)
    //CurHp     =   ;           //百分比//当前生命值百分值(Health Point)
    //Shield    =   ;           //数值  //护盾值
    //MaxShield =   ;           //数值  //最大护盾值
    //Mp        = 5 ;           //数值  //元素能量(Magic Point)
    //MaxMp     =   ;           //数值  //最大元素能量(Magic Point)
    //CurMp     =   ;           //百分比//当前元素能量百分值(Magic Point)
    //Atk       = 6 ;           //数值  //攻击力(Attack)
    //Def       = 7 ;           //数值  //防御力(Defense)
    //Acc       = 8 ;           //百分比//命中几率(Accuracy)
    //Dod       = 9 ;           //百分比//闪避几率(Dodge)
    //ElemAdd   = 10;           //百分比//元素能力加成(Element Addition)
    //AtkSpd    = 11;           //百分比//攻击速度(Attack Speed)
    //Cthr      = 12;           //百分比//暴击几率(Critical Hit Rate)
    //Cthd      = 13;           //百分比//暴击伤害(Critical Hit Damage)
    //MoSpd     = 14;           //数值  //移动速度(Movement Speed)
    //HpRes     = 15;           //数值  //每10秒生命恢复(Hp restore every 10 seconds)
    //MpRes     = 16;           //数值  //每10秒能量恢复(Mp restore every 10 seconds)
    //CodAc     = 17;           //百分比//冷却加速(Cooldown acceleration)
    //FirAtk    = 18;           //数值  //火元素攻击(Fire Attack)
    //IceAtk    = 19;           //数值  //冰元素攻击(Ice Attack)
    //PoiAtk    = 20;           //数值  //毒元素攻击(Poison Attack)
    //EleAtk    = 21;           //数值  //电元素攻击(Electricity Attack)
    //LigAtk    = 22;           //数值  //光元素攻击(Light Attack)
    //DarAtk    = 23;           //数值  //暗元素攻击(Darkness Attack)
    //FirDef    = 24;           //数值  //火元素抗性(Fire Defense)
    //IceDef    = 25;           //数值  //冰元素抗性(Ice Defense)
    //PoiDef    = 26;           //数值  //毒元素抗性(Poison Defense)
    //EleDef    = 27;           //数值  //电元素抗性(Electricity Defense)
    //LigDef    = 28;           //数值  //光元素抗性(Light Defense)
    //DarDef    = 29;           //数值  //暗元素抗性(Darkness Defense)

    /// <summary>数值 力量强度(Strength)                            </summary>
    private float str;

    /// <summary>数值 敏捷强度(Agility)                             </summary>
    private float agi;

    /// <summary>数值 体力强度(Stamina)                             </summary>
    private float sta;

    /// <summary>数值 元素亲和(Element)                             </summary>
    private float elem;

    /// <summary>数值 生命值(Health Point)                          </summary>
    private float hp;

    /// <summary>数值 最大生命值(Health Point)                          </summary>
    private float maxHp;

    /// <summary>百分 生命百分值(Accuracy)                          </summary>
    private float curHp = 1;

    /// <summary>数值 元素能量(Magic Point)                         </summary>
    private float mp;

    /// <summary>数值 最大元素能量(Health Point)                          </summary>
    private float maxMp;

    /// <summary>百分 生命百分值(Accuracy)                          </summary>
    private float curMp = 1;

    /// <summary>数值 攻击力(Attack)                                </summary>
    private float atk;

    /// <summary>数值 防御力(Defense)                               </summary>
    private float def;

    /// <summary>百分 命中几率(Accuracy)                            </summary>
    private float acc;

    /// <summary>百分 闪避几率(Dodge)                               </summary>
    private float dod;

    /// <summary>百分 元素能力加成(Element Addition)                </summary>
    private float elemAdd;

    /// <summary>百分 攻击速度(Attack Speed)                        </summary>
    private float atkSpd;

    /// <summary>百分 暴击几率(Critical Hit Rate)                   </summary>
    private float cthr;

    /// <summary>百分 暴击伤害(Critical Hit Damage)                 </summary>
    private float cthd;

    /// <summary>数值 移动速度(Movement Speed)                      </summary>
    private float moSpd;

    /// <summary>数值 移动速度(Movement Speed)                      </summary>
    private float addMoSpd;

    /// <summary>数值 每10秒生命恢复(Hp restore every 10 seconds)   </summary>
    private float hpRes;

    /// <summary>数值 每10秒能量恢复(Mp restore every 10 seconds)   </summary>
    private float mpRes;

    /// <summary>百分 冷却加速(Cooldown acceleration)               </summary>
    private float codAc;

    /// <summary>数值 火元素攻击(Fire Attack)                       </summary>
    private float firAtk;

    /// <summary>数值 冰元素攻击(Ice Attack)                        </summary>
    private float iceAtk;

    /// <summary>数值 毒元素攻击(Poison Attack)                     </summary>
    private float poiAtk;

    /// <summary>数值 电元素攻击(Electricity Attack)                </summary>
    private float eleAtk;

    /// <summary>数值 光元素攻击(Light Attack)                      </summary>
    private float ligAtk;

    /// <summary>数值 暗元素攻击(Darkness Attack)                   </summary>
    private float darAtk;

    /// <summary>数值 火元素抗性(Fire Defense)                      </summary>
    private float firDef;

    /// <summary>数值 冰元素抗性(Ice Defense)                       </summary>
    private float iceDef;

    /// <summary>数值 毒元素抗性(Poison Defense)                    </summary>
    private float poiDef;

    /// <summary>数值 电元素抗性(Electricity Defense)               </summary>
    private float eleDef;

    /// <summary>数值 光元素抗性(Light Defense)                     </summary>
    private float ligDef;

    /// <summary>数值 暗元素抗性(Darkness Defense)                  </summary>
    private float darDef;

    /// <summary>数值 重量                                          </summary>
    private float weight;

    /// <summary>数值 护盾值(Accuracy)                          </summary>
    private float shield;

    /// <summary>数值 最大护盾值(Accuracy)                          </summary>
    private float maxShield;

    /// <summary>百分 元素免疫(Accuracy)                          </summary>
    private float immune;

    /// <summary>百分 物理免疫(Accuracy)                          </summary>
    private float pysImmune;

    /// <summary>数值  //力量强度(Strength)                               </summary>
    public float Str { get { return str; } set { str = value; } }

    /// <summary>数值  //敏捷强度(Agility)                                </summary>
    public float Agi { get { return agi; } set { agi = value; } }

    /// <summary>数值  //体力强度(Stamina)                                </summary>
    public float Sta { get { return sta; } set { sta = value; } }

    /// <summary>数值  //元素亲和(Element)                                </summary>
    public float Elem { get { return elem; } set { elem = value; } }

    /// <summary>数值  //生命值(Health Point)                             </summary>
    public float Hp
    {
        get { return hp; }
        set
        {
            hp = ((float)(value)).toInt();
            if (MaxHp > 0)
            {
                if (hp > MaxHp)
                {
                    hp = MaxHp;
                    CurHp = 1;
                }
                else if (hp <= 0)
                {
                    hp = 0;
                    CurHp = 0;
                }
                else if (hp > 0)
                {
                    CurHp = Mathf.Clamp((hp / MaxHp), 0, 1);
                }
            }
        }
    }

    /// <summary>数值  //最大生命值(Health Point)                         </summary>
    public float MaxHp { get { return maxHp; } set { maxHp = value; } }

    /// <summary>百分比//当前生命值百分值(Health Point)                   </summary>
    public float CurHp { get { return curHp; } set { curHp = value; } }

    /// <summary>数值  //元素能量(Magic Point)                            </summary>
    public float Mp
    {
        get { return mp; }
        set
        {
            mp = value;
            if (MaxMp > 0)
            {
                if (mp > MaxMp)
                {
                    mp = MaxMp;
                    CurMp = 1;
                }
                else if (mp <= 0)
                {
                    mp = 0;
                    CurMp = 0;
                }
                else if (mp > 0)
                {
                    CurMp = Mathf.Clamp((mp / MaxMp), 0, 1);
                }
            }
        }
    }

    /// <summary>数值  //最大元素能量(Magic Point)                        </summary>
    public float MaxMp { get { return maxMp; } set { maxMp = value; } }

    /// <summary>百分比//当前元素能量百分值(Magic Point)                  </summary>
    public float CurMp { get { return curMp; } set { curMp = value; } }

    /// <summary>数值  //攻击力(Attack)                                   </summary>
    public float Atk { get { return atk; } set { atk = value; } }

    /// <summary>数值  //防御力(Defense)                                  </summary>
    public float Def { get { return def; } set { def = value; } }

    /// <summary>百分比//命中几率(Accuracy)                               </summary>
    public float Acc { get { return acc; } set { acc = value; } }

    /// <summary>百分比//闪避几率(Dodge)                                  </summary>
    public float Dod { get { return dod; } set { dod = value; } }

    /// <summary>百分比//元素能力加成(Element Addition)                   </summary>
    public float ElemAdd { get { return elemAdd; } set { elemAdd = value; } }

    /// <summary>百分比//攻击速度(Attack Speed)                           </summary>
    public float AtkSpd { get { return atkSpd; } set { atkSpd = value; } }

    /// <summary>百分比//暴击几率(Critical Hit Rate)                      </summary>
    public float Cthr { get { return cthr; } set { cthr = value; } }

    /// <summary>百分比//暴击伤害(Critical Hit Damage)                    </summary>
    public float Cthd { get { return cthd; } set { cthd = value; } }

    /// <summary>数值  //移动速度(Movement Speed)                         </summary>
    public float MoSpd { get { return moSpd; } set { moSpd = value; } }

    /// <summary>百分比 //移动速度增加量(Movement Speed)                   </summary>
    public float AddMoSpd { get { return addMoSpd; } set { addMoSpd = value; } }

    /// <summary>数值  //每10秒生命恢复(Hp restore every 10 seconds)      </summary>
    public float HpRes { get { return hpRes; } set { hpRes = value; } }

    /// <summary>数值  //每10秒能量恢复(Mp restore every 10 seconds)      </summary>
    public float MpRes { get { return mpRes; } set { mpRes = value; } }

    /// <summary>百分比//冷却加速(Cooldown acceleration)                  </summary>
    public float CodAc { get { return codAc; } set { codAc = value; } }

    /// <summary>数值  //火元素攻击(Fire Attack)                          </summary>
    public float FirAtk { get { return firAtk; } set { firAtk = value; } }

    /// <summary>数值  //冰元素攻击(Ice Attack)                           </summary>
    public float IceAtk { get { return iceAtk; } set { iceAtk = value; } }

    /// <summary>数值  //毒元素攻击(Poison Attack)                        </summary>
    public float PoiAtk { get { return poiAtk; } set { poiAtk = value; } }

    /// <summary>数值  //电元素攻击(Electricity Attack)                   </summary>
    public float EleAtk { get { return eleAtk; } set { eleAtk = value; } }

    /// <summary>数值  //光元素攻击(Light Attack)                         </summary>
    public float LigAtk { get { return ligAtk; } set { ligAtk = value; } }

    /// <summary>数值  //暗元素攻击(Darkness Attack)                      </summary>
    public float DarAtk { get { return darAtk; } set { darAtk = value; } }

    /// <summary>数值  //火元素抗性(Fire Defense)                         </summary>
    public float FirDef { get { return firDef; } set { firDef = value; } }

    /// <summary>数值  //冰元素抗性(Ice Defense)                          </summary>
    public float IceDef { get { return iceDef; } set { iceDef = value; } }

    /// <summary>数值  //毒元素抗性(Poison Defense)                       </summary>
    public float PoiDef { get { return poiDef; } set { poiDef = value; } }

    /// <summary>数值  //电元素抗性(Electricity Defense)                  </summary>
    public float EleDef { get { return eleDef; } set { eleDef = value; } }

    /// <summary>数值  //光元素抗性(Light Defense)                        </summary>
    public float LigDef { get { return ligDef; } set { ligDef = value; } }

    /// <summary>数值  //暗元素抗性(Darkness Defense)                     </summary>
    public float DarDef { get { return darDef; } set { darDef = value; } }

    /// <summary>数值  //重量                                             </summary>
    public float Weight { get { return weight; } set { weight = value; } }

    /// <summary>数值//当前护盾          (Health Point)                   </summary>
    public float Shield { get { return shield; } set { shield = value; } }

    /// <summary>数值//当前护盾          (Health Point)                   </summary>
    public float MaxShield { get { return maxShield; } set { maxShield = value; } }

    /// <summary>百分//元素免疫          (Health Point)                   </summary>
    public float Immune { get { return immune; } set { immune = value; } }
    /// <summary>百分//物理免疫          (Health Point)                   </summary>
    public float PysImmune { get { return pysImmune; } set { pysImmune = value; } }
    public void SetAdd(AttrType types, float v)
    {
        switch (types)
        {
            case AttrType.Str: Str += v; break;
            case AttrType.Agi: Agi += v; break;
            case AttrType.Sta: Sta += v; break;
            case AttrType.Elem: Elem += v; break;
            case AttrType.Hp: Hp += v; break;
            case AttrType.Mp: Mp += v; break;
            case AttrType.Atk: Atk += v; break;
            case AttrType.Def: Def += v; break;
            case AttrType.Acc: Acc += v; break;
            case AttrType.Dod: Dod += v; break;
            case AttrType.ElemAdd: ElemAdd += v; break;
            case AttrType.AtkSpd: AtkSpd += v; break;
            case AttrType.Cthr: Cthr += v; break;
            case AttrType.Cthd: Cthd += v; break;
            case AttrType.MoSpd: MoSpd += v; break;
            case AttrType.HpRes: HpRes += v; break;
            case AttrType.MpRes: MpRes += v; break;
            case AttrType.CodAc: CodAc += v; break;
            case AttrType.FirAtk: FirAtk += v; break;
            case AttrType.IceAtk: IceAtk += v; break;
            case AttrType.PoiAtk: PoiAtk += v; break;
            case AttrType.EleAtk: EleAtk += v; break;
            case AttrType.LigAtk: LigAtk += v; break;
            case AttrType.DarAtk: DarAtk += v; break;
            case AttrType.FirDef: FirDef += v; break;
            case AttrType.IceDef: IceDef += v; break;
            case AttrType.PoiDef: PoiDef += v; break;
            case AttrType.EleDef: EleDef += v; break;
            case AttrType.LigDef: LigDef += v; break;
            case AttrType.DarDef: DarDef += v; break;
            case AttrType.Weight: Weight += v; break;

            default:
                AddSetAdd(types, v);
                break;
        }
    }

    public void Set(AttrType types, float v)
    {
        switch (types)
        {
            case AttrType.Str: Str = v; break;
            case AttrType.Agi: Agi = v; break;
            case AttrType.Sta: Sta = v; break;
            case AttrType.Elem: Elem = v; break;
            case AttrType.Hp: Hp = v; break;
            case AttrType.Mp: Mp = v; break;
            case AttrType.Atk: Atk = v; break;
            case AttrType.Def: Def = v; break;
            case AttrType.Acc: Acc = v; break;
            case AttrType.Dod: Dod = v; break;
            case AttrType.ElemAdd: ElemAdd = v; break;
            case AttrType.AtkSpd: AtkSpd = v; break;
            case AttrType.Cthr: Cthr = v; break;
            case AttrType.Cthd: Cthd = v; break;
            case AttrType.MoSpd: MoSpd = v; break;
            case AttrType.HpRes: HpRes = v; break;
            case AttrType.MpRes: MpRes = v; break;
            case AttrType.CodAc: CodAc = v; break;
            case AttrType.FirAtk: FirAtk = v; break;
            case AttrType.IceAtk: IceAtk = v; break;
            case AttrType.PoiAtk: PoiAtk = v; break;
            case AttrType.EleAtk: EleAtk = v; break;
            case AttrType.LigAtk: LigAtk = v; break;
            case AttrType.DarAtk: DarAtk = v; break;
            case AttrType.FirDef: FirDef = v; break;
            case AttrType.IceDef: IceDef = v; break;
            case AttrType.PoiDef: PoiDef = v; break;
            case AttrType.EleDef: EleDef = v; break;
            case AttrType.LigDef: LigDef = v; break;
            case AttrType.DarDef: DarDef = v; break;
            case AttrType.Weight: Weight = v; break;
            default:
                AddSet(types, v);
                break;
        }
    }

    public float Get(AttrType types)
    {
        switch (types)
        {
            case AttrType.Str: return Str;
            case AttrType.Agi: return Agi;
            case AttrType.Sta: return Sta;
            case AttrType.Elem: return Elem;
            case AttrType.Hp: return Hp;
            case AttrType.Mp: return Mp;
            case AttrType.Atk: return Atk;
            case AttrType.Def: return Def;
            case AttrType.Acc: return Acc;
            case AttrType.Dod: return Dod;
            case AttrType.ElemAdd: return ElemAdd;
            case AttrType.AtkSpd: return AtkSpd;
            case AttrType.Cthr: return Cthr;
            case AttrType.Cthd: return Cthd;
            case AttrType.MoSpd: return MoSpd;
            case AttrType.HpRes: return HpRes;
            case AttrType.MpRes: return MpRes;
            case AttrType.CodAc: return CodAc;
            case AttrType.FirAtk: return FirAtk;
            case AttrType.IceAtk: return IceAtk;
            case AttrType.PoiAtk: return PoiAtk;
            case AttrType.EleAtk: return EleAtk;
            case AttrType.LigAtk: return LigAtk;
            case AttrType.DarAtk: return DarAtk;
            case AttrType.FirDef: return FirDef;
            case AttrType.IceDef: return IceDef;
            case AttrType.PoiDef: return PoiDef;
            case AttrType.EleDef: return EleDef;
            case AttrType.LigDef: return LigDef;
            case AttrType.DarDef: return DarDef;
            case AttrType.Weight: return Weight;
            default:
                return AddGet(types);
        }
    }

    /// <summary>
    /// 获取名字
    /// </summary>
    public string GetName(AttrType types)
    {
        string name = "";
        switch (types)
        {
            case AttrType.Str: name = TypeGetName(AttrType.Str); ; break;
            case AttrType.Agi: name = TypeGetName(AttrType.Agi); ; break;
            case AttrType.Sta: name = TypeGetName(AttrType.Sta); ; break;
            case AttrType.Elem: name = TypeGetName(AttrType.Elem); ; break;
            case AttrType.Hp: name = TypeGetName(AttrType.Hp); ; break;
            case AttrType.Mp: name = TypeGetName(AttrType.Mp); ; break;
            case AttrType.Atk: name = TypeGetName(AttrType.Atk); ; break;
            case AttrType.Def: name = TypeGetName(AttrType.Def); ; break;
            case AttrType.Acc: name = TypeGetName(AttrType.Acc); ; break;
            case AttrType.Dod: name = TypeGetName(AttrType.Dod); ; break;
            case AttrType.ElemAdd: name = TypeGetName(AttrType.ElemAdd); ; break;
            case AttrType.AtkSpd: name = TypeGetName(AttrType.AtkSpd); ; break;
            case AttrType.Cthr: name = TypeGetName(AttrType.Cthr); ; break;
            case AttrType.Cthd: name = TypeGetName(AttrType.Cthd); ; break;
            case AttrType.MoSpd: name = TypeGetName(AttrType.MoSpd); ; break;
            case AttrType.HpRes: name = TypeGetName(AttrType.HpRes); ; break;
            case AttrType.MpRes: name = TypeGetName(AttrType.MpRes); ; break;
            case AttrType.CodAc: name = TypeGetName(AttrType.CodAc); ; break;
            case AttrType.FirAtk: name = TypeGetName(AttrType.FirAtk); ; break;
            case AttrType.IceAtk: name = TypeGetName(AttrType.IceAtk); ; break;
            case AttrType.PoiAtk: name = TypeGetName(AttrType.PoiAtk); ; break;
            case AttrType.EleAtk: name = TypeGetName(AttrType.EleAtk); ; break;
            case AttrType.LigAtk: name = TypeGetName(AttrType.LigAtk); ; break;
            case AttrType.DarAtk: name = TypeGetName(AttrType.DarAtk); ; break;
            case AttrType.FirDef: name = TypeGetName(AttrType.FirDef); ; break;
            case AttrType.IceDef: name = TypeGetName(AttrType.IceDef); ; break;
            case AttrType.PoiDef: name = TypeGetName(AttrType.PoiDef); ; break;
            case AttrType.EleDef: name = TypeGetName(AttrType.EleDef); ; break;
            case AttrType.LigDef: name = TypeGetName(AttrType.LigDef); ; break;
            case AttrType.DarDef: name = TypeGetName(AttrType.DarDef); ; break;
            case AttrType.Weight: name = TypeGetName(AttrType.Weight); ; break;
            case AttrType.Shield: name = TypeGetName(AttrType.Shield); ; break;
            default:
                AddGetName(types);
                break;
        }
        return name;
    }

    /// <summary>
    /// 获取值的名字
    /// </summary>
    public string GetValueName(AttrType types)
    {
        string name = string.Empty;
        switch (types)
        {
            case AttrType.Str: name = TypeGetValueName(AttrType.Str, Str); break;            //数值
            case AttrType.Agi: name = TypeGetValueName(AttrType.Agi, Agi); break;            //数值
            case AttrType.Sta: name = TypeGetValueName(AttrType.Sta, Sta); break;            //数值
            case AttrType.Elem: name = TypeGetValueName(AttrType.Elem, Elem); break;          //数值
            case AttrType.Hp: name = TypeGetValueName(AttrType.Hp, Hp); break;              //数值
            case AttrType.Mp: name = TypeGetValueName(AttrType.Mp, Mp); break;              //数值
            case AttrType.Atk: name = TypeGetValueName(AttrType.Atk, Atk); break;            //数值
            case AttrType.Def: name = TypeGetValueName(AttrType.Def, Def); break;            //数值
            case AttrType.Acc: name = TypeGetValueName(AttrType.Acc, Acc); break;         //百分比
            case AttrType.Dod: name = TypeGetValueName(AttrType.Dod, Dod); break;         //百分比
            case AttrType.ElemAdd: name = TypeGetValueName(AttrType.ElemAdd, ElemAdd); break; //百分比
            case AttrType.AtkSpd: name = TypeGetValueName(AttrType.AtkSpd, AtkSpd); break;   //百分比
            case AttrType.Cthr: name = TypeGetValueName(AttrType.Cthr, Cthr); break;       //百分比
            case AttrType.Cthd: name = TypeGetValueName(AttrType.Cthd, Cthd); break;       //百分比
            case AttrType.MoSpd: name = TypeGetValueName(AttrType.MoSpd, AddMoSpd); break;  //百分比
            case AttrType.HpRes: name = TypeGetValueName(AttrType.HpRes, HpRes); break;        //数值
            case AttrType.MpRes: name = TypeGetValueName(AttrType.MpRes, MpRes); break;        //数值
            case AttrType.CodAc: name = TypeGetValueName(AttrType.CodAc, CodAc); break;     //百分比
            case AttrType.FirAtk: name = TypeGetValueName(AttrType.FirAtk, FirAtk); break;      //数值
            case AttrType.IceAtk: name = TypeGetValueName(AttrType.IceAtk, IceAtk); break;      //数值
            case AttrType.PoiAtk: name = TypeGetValueName(AttrType.PoiAtk, PoiAtk); break;      //数值
            case AttrType.EleAtk: name = TypeGetValueName(AttrType.EleAtk, EleAtk); break;      //数值
            case AttrType.LigAtk: name = TypeGetValueName(AttrType.LigAtk, LigAtk); break;      //数值
            case AttrType.DarAtk: name = TypeGetValueName(AttrType.DarAtk, DarAtk); break;      //数值
            case AttrType.FirDef: name = TypeGetValueName(AttrType.FirDef, FirDef); break;      //数值
            case AttrType.IceDef: name = TypeGetValueName(AttrType.IceDef, IceDef); break;      //数值
            case AttrType.PoiDef: name = TypeGetValueName(AttrType.PoiDef, PoiDef); break;      //数值
            case AttrType.EleDef: name = TypeGetValueName(AttrType.EleDef, EleDef); break;      //数值
            case AttrType.LigDef: name = TypeGetValueName(AttrType.LigDef, LigDef); break;      //数值
            case AttrType.DarDef: name = TypeGetValueName(AttrType.DarDef, DarDef); break;      //数值
            case AttrType.Weight: name = TypeGetValueName(AttrType.Weight, Weight); break;      //数值
            case AttrType.Shield: name = TypeGetValueName(AttrType.Shield, Shield); break;      //数值
            default:
                name = AddGetValue(types);
                break;
        }
        return name;
    }

    public static string TypeGetName(AttrType types)
    {
        string name = "";
        switch (types)
        {
            case AttrType.Str: name = "力量"; break;
            case AttrType.Agi: name = "敏捷"; break;
            case AttrType.Sta: name = "体力"; break;
            case AttrType.Elem: name = "智力"; break;
            case AttrType.Hp: name = "生命值"; break;
            case AttrType.Mp: name = "能量"; break;
            case AttrType.Atk: name = "攻击力"; break;
            case AttrType.Def: name = "防御力"; break;
            case AttrType.Acc: name = "命中等级"; break;
            case AttrType.Dod: name = "闪避等级"; break;
            case AttrType.ElemAdd: name = "元素伤害加成"; break;
            case AttrType.AtkSpd: name = "攻击速度"; break;
            case AttrType.Cthr: name = "暴击几率"; break;
            case AttrType.Cthd: name = "暴击伤害"; break;
            case AttrType.MoSpd: name = "移动速度"; break;
            case AttrType.HpRes: name = "回血加成"; break;
            case AttrType.MpRes: name = "能量恢复"; break;
            case AttrType.CodAc: name = "冷却加速"; break;
            case AttrType.FirAtk: name = "火元素攻击"; break;
            case AttrType.IceAtk: name = "冰元素攻击"; break;
            case AttrType.PoiAtk: name = "毒元素攻击"; break;
            case AttrType.EleAtk: name = "电元素攻击"; break;
            case AttrType.LigAtk: name = "光元素攻击"; break;
            case AttrType.DarAtk: name = "暗元素攻击"; break;
            case AttrType.FirDef: name = "火元素抗性"; break;
            case AttrType.IceDef: name = "冰元素抗性"; break;
            case AttrType.PoiDef: name = "毒元素抗性"; break;
            case AttrType.EleDef: name = "电元素抗性"; break;
            case AttrType.LigDef: name = "光元素抗性"; break;
            case AttrType.DarDef: name = "暗元素抗性"; break;
            case AttrType.Weight: name = "重量"; break;
            case AttrType.Shield: name = "护盾"; break;
            default:

                break;
        }
        return name;
    }

    public static string TypeGetValueName(AttrType types, float v)
    {
        string name = string.Empty;
        switch (types)
        {
            case AttrType.Str: name = v.toString(0); break;        //数值
            case AttrType.Agi: name = v.toString(0); break;        //数值
            case AttrType.Sta: name = v.toString(0); break;        //数值
            case AttrType.Elem: name = v.toString(0); break;       //数值
            case AttrType.Hp: name = v.toString(0); break;         //数值
            case AttrType.Mp: name = v.toString(0); break;         //数值
            case AttrType.Atk: name = v.toString(0); break;        //数值
            case AttrType.Def: name = v.toString(0); break;        //数值
            case AttrType.Acc: name = (v * 100).toString(0); break; //数值
            case AttrType.Dod: name = (v * 100).toString(0); break; //数值
            case AttrType.ElemAdd: name = v.toPercentage(); break; //百分比
            case AttrType.AtkSpd: name = v.toPercentage(); break;  //百分比
            case AttrType.Cthr: name = v.toPercentage(); break;    //百分比
            case AttrType.Cthd: name = v.toPercentage(); break;    //百分比
            case AttrType.MoSpd: name = v.toPercentage(); break;   //百分比
            case AttrType.HpRes: name = v.toString(0); break;      //数值
            case AttrType.MpRes: name = v.toString(0); break;      //数值
            case AttrType.CodAc: name = v.toPercentage(); break;   //百分比
            case AttrType.FirAtk: name = v.toString(0); break;      //数值
            case AttrType.IceAtk: name = v.toString(0); break;      //数值
            case AttrType.PoiAtk: name = v.toString(0); break;      //数值
            case AttrType.EleAtk: name = v.toString(0); break;      //数值
            case AttrType.LigAtk: name = v.toString(0); break;      //数值
            case AttrType.DarAtk: name = v.toString(0); break;      //数值
            case AttrType.FirDef: name = v.toString(0); break;      //数值
            case AttrType.IceDef: name = v.toString(0); break;      //数值
            case AttrType.PoiDef: name = v.toString(0); break;      //数值
            case AttrType.EleDef: name = v.toString(0); break;      //数值
            case AttrType.LigDef: name = v.toString(0); break;      //数值
            case AttrType.DarDef: name = v.toString(0); break;      //数值
            case AttrType.Weight: name = v.toString(0); break;      //数值
            case AttrType.Shield: name = v.toString(0); break;      //数值
            default:

                break;
        }
        return name;
    }

    #region 扩展方法

    /// <summary>
    ///扩展值名字方法
    /// </summary>
    /// <param name="types"></param>
    /// <returns></returns>
    protected string AddGetValue(AttrType types) { return string.Empty; }

    /// <summary>
    ///扩展名字方法
    /// </summary>
    /// <param name="types"></param>
    /// <returns></returns>
    protected virtual string AddGetName(AttrType types) { return string.Empty; }

    /// <summary>
    /// 扩展属性
    /// </summary>
    protected virtual void AddSetAdd(AttrType types, float v) { }

    /// <summary>
    /// 扩展添加
    /// </summary>
    /// <param name="types"></param>
    /// <param name="v"></param>
    protected virtual void AddSet(AttrType types, float v) { }

    /// <summary>
    /// 扩展属性
    /// </summary>
    protected virtual float AddGet(AttrType types) { return 0; }

    #endregion 扩展方法

    public float this[int index] { get { return Get((AttrType)index); } set { Set((AttrType)index, value); } }

    public float this[AttrType index] { get { return Get(index); } set { Set(index, value); } }

    public string toString()
    {
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < (int)AttrType.Max; i++)
        {
            AttrType at = (AttrType)i;
            sb.Append(GetName(at));
            sb.Append(":");
            sb.Append(GetValueName(at));
            sb.Append("  ");
        }
        return sb.ToString();
    }

    public void Copy(ref Attr ToValue)
    {
        ToValue.Str = (float)Str;
        ToValue.Agi = (float)Agi;
        ToValue.Sta = (float)Sta;
        ToValue.Elem = (float)Elem;
        ToValue.Hp = (float)Hp;
        ToValue.MaxHp = (float)MaxHp;
        ToValue.CurHp = (float)CurHp;
        ToValue.Shield = (float)Shield;
        ToValue.MaxShield = (float)MaxShield;
        ToValue.Mp = (float)Mp;
        ToValue.MaxMp = (float)MaxMp;
        ToValue.CurMp = (float)CurMp;
        ToValue.Atk = (float)Atk;
        ToValue.Def = (float)Def;
        ToValue.Acc = (float)Acc;
        ToValue.Dod = (float)Dod;
        ToValue.ElemAdd = (float)ElemAdd;
        ToValue.AtkSpd = (float)AtkSpd;
        ToValue.Cthr = (float)Cthr;
        ToValue.Cthd = (float)Cthd;
        ToValue.MoSpd = (float)MoSpd;
        ToValue.HpRes = (float)HpRes;
        ToValue.MpRes = (float)MpRes;
        ToValue.CodAc = (float)CodAc;
        ToValue.FirAtk = (float)FirAtk;
        ToValue.IceAtk = (float)IceAtk;
        ToValue.PoiAtk = (float)PoiAtk;
        ToValue.EleAtk = (float)EleAtk;
        ToValue.LigAtk = (float)LigAtk;
        ToValue.DarAtk = (float)DarAtk;
        ToValue.FirDef = (float)FirDef;
        ToValue.IceDef = (float)IceDef;
        ToValue.PoiDef = (float)PoiDef;
        ToValue.EleDef = (float)EleDef;
        ToValue.LigDef = (float)LigDef;
        ToValue.DarDef = (float)DarDef;
    }
}

/// <summary>
/// 武器附加属性
/// </summary>
public class WeaponAddAttr : Attr
{
}
/// <summary>
/// 单件装备属性
/// </summary>
public class ArmorAttr : Attr
{
    /// <summary>
    /// 获取有效的属性
    /// </summary>
    /// <returns></returns>
    public List<AttrType> GetValidAttrType()
    {
        List<AttrType> list = new List<AttrType>();
        for (int i = 0; i < (int)AttrType.Max; i++)
        {
            AttrType t = i.toEnum<AttrType>();
            if (this[t] != 0)
            {
                list.Add(t);
            }
        }
        return list;
    }
}

/// <summary>
/// 武器额外属性
/// </summary>
public class WeaponExtraAttr : Attr
{
}


/// <summary>
/// 基本属性
/// </summary>
public abstract class BaseAttr
{
    public Attr m_BaseAttr;              // 基本數值

    public Attr m_CurAttr;               // 最终數值
}

/// <summary>
/// 武器属性
/// </summary>
public class WeaponAttr : BaseAttr
{
   
    /// <summary>
    /// 武器附加数值
    /// </summary>
    public WeaponAddAttr m_AppendAttr;

    /// <summary>
    /// 武器额外数值
    /// </summary>
    public WeaponExtraAttr m_ExtraAttr;

    //增加特有属性
    public WeaponAttr()
    {
        m_BaseAttr = new Attr();             //武器基本数值
        m_CurAttr = new WeaponAddAttr();              //武器最终数值
        m_AppendAttr = new WeaponAddAttr();
        m_ExtraAttr = new WeaponExtraAttr();
    }
}
